package com.yuexun.dhdoctor.module.Contract.presenter.impl;


import android.util.Log;

import com.yuexun.dhdoctor.base.BaseEntity;
import com.yuexun.dhdoctor.module.Contract.bean.GroupDataBean;
import com.yuexun.dhdoctor.module.Contract.model.IDepartmentModel;
import com.yuexun.dhdoctor.module.Contract.presenter.IDepartmentPresenter;
import com.yuexun.dhdoctor.module.Contract.ui.view.IDepartmentView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by work-jx on 2016/7/19.
 */
public class DepartmentPresenter implements IDepartmentPresenter {
    private IDepartmentView view;
    private IDepartmentModel model;

    //记录Log
//    private final Logger log = ProUtil.getLogger(LoginPresneter.class);

    public DepartmentPresenter(IDepartmentModel model, IDepartmentView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void getAllDepartment(Map<String, String> praise) {
        model.getAllDepartment(praise)
                .retry(3)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<GroupDataBean>>() {
                               @Override
                               public void onCompleted() {

                               }

                               @Override
                               public void onError(Throwable e) {
                                   ViewInject.toast("请检查网络状态");
                               }

                               @Override
                               public void onNext(BaseEntity<GroupDataBean> groupBean) {
                                   view.showGroupDatas(groupBean);
                               }
                           }
                );
    }

    @Override
    public void getGroupDatas(Map<String, String> praise) {
        model.getDepartmentDatas(praise)
//                .retry(3)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<GroupDataBean>>() {
                               @Override
                               public void onCompleted() {

                               }

                               @Override
                               public void onError(Throwable e) {
                                   Log.e("jx", e.getMessage());
                               }

                               @Override
                               public void onNext(BaseEntity<GroupDataBean> groupBean) {
                                   view.showGroupDatas(groupBean);
                               }
                           }
                );
    }
}
